package com.yowasa.xiuxian.entity.bo.user;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yowasa.xiuxian.entity.enums.StageEnum;
import com.yowasa.xiuxian.util.RandomUtil;
import com.yowasa.xiuxian.util.StrUtil;
import lombok.Data;

import java.io.Serializable;

@Data
public class UserBattle implements Serializable {
    //血量上限
    private int hp;
    //当前血量
    private int chp;
    //灵气上限
    private int mp;
    //当前灵气
    private int cmp;
    //攻击能力
    private int atk;
    //术法能力
    private int spell;
    //防御能力
    private int def;
    //术法抗性
    private int res;
    //免疫能力
    private int imm;
    //速度
    private int spd;

    @JsonIgnore
    public String getDesc() {
        String msg = "HP:${chp}/${hp} MP:${cmp}/${mp}\n" +
                "攻击|术法:${atk}|${spell} 物抗|术抗:${def}|${res}\n" +
                "免疫:${imm} 速度:${spd}";
        return StrUtil.processTemplate(msg, this);
    }

    @JsonIgnore
    public String getUpDesc() {
        String msg = "HP+${chp} MP+${cmp}\n" +
                "攻击+${atk} 术法+${spell} \n" +
                "物抗+${def} 术抗+${res}\n" +
                "免疫+${imm} 速度+${spd}";
        return StrUtil.processTemplate(msg, this);
    }

    public static UserBattle genBattleAttr(UserAttr attr) {
        UserBattle userBattle = new UserBattle();
        userBattle.setHp(50 + attr.getCon() / 2 + (RandomUtil.randomInt(attr.getCon() / 2)));
        userBattle.setMp(10 + attr.getInts() / 4 + RandomUtil.randomInt(attr.getInts() / 2));
        userBattle.setChp(userBattle.getHp());
        userBattle.setCmp(userBattle.getMp());
        userBattle.setAtk(attr.getStr() / 10 + RandomUtil.randomInt(attr.getStr()) / 10 + RandomUtil.randomInt(attr.getDex()) / 10);
        userBattle.setSpell(attr.getInts() / 10 + RandomUtil.randomInt(attr.getInts()) / 10);
        userBattle.setDef(attr.getCon() / 10 + RandomUtil.randomInt(attr.getCon()) / 10 + RandomUtil.randomInt(attr.getDex()) / 10);
        userBattle.setRes(attr.getInts() / 10 + RandomUtil.randomInt(attr.getInts()) / 10);
        userBattle.setImm(attr.getCon() / 10 + RandomUtil.randomInt(attr.getCon()) / 10);
        userBattle.setSpd(attr.getDex() / 2 + RandomUtil.randomInt(attr.getDex()) / 2);
        return userBattle;
    }

    //根据四维属性，和境界倍率计算提升值
    //力量，敏捷，体质，气感
    public static UserBattle genUpBattleAttrByRate(UserAttr attr, double rate) {
        UserBattle userBattle = new UserBattle();
        userBattle.setHp((int) (rate * (50 + attr.getCon() / 2 + (RandomUtil.randomInt(attr.getCon() / 2)))));
        userBattle.setMp((int) (rate * (10 + attr.getInts() / 4 + RandomUtil.randomInt(attr.getInts() / 2))));
        userBattle.setChp(userBattle.getHp());
        userBattle.setCmp(userBattle.getMp());
        userBattle.setAtk((int) (rate * (attr.getStr() / 10 + RandomUtil.randomInt(attr.getStr()) / 10 + RandomUtil.randomInt(attr.getDex())/ 10)));
        userBattle.setSpell((int) (rate * (attr.getInts() / 10 + RandomUtil.randomInt(attr.getInts()) / 10 + RandomUtil.randomInt(attr.getUnd())/ 10)));
        userBattle.setDef((int) (rate * (attr.getCon() / 10 + RandomUtil.randomInt(attr.getCon()) / 10 + RandomUtil.randomInt(attr.getDex())/ 10)));
        userBattle.setRes((int) (rate * (attr.getInts() / 10 + RandomUtil.randomInt(attr.getInts()) / 10 + RandomUtil.randomInt(attr.getUnd())/ 10)));
        userBattle.setImm((int) (rate * (attr.getCon() / 10 + RandomUtil.randomInt(attr.getCon()) / 10)));
        userBattle.setSpd((int) (rate * (attr.getDex() / 2 + RandomUtil.randomInt(attr.getDex()) / 2)));
        return userBattle;
    }

    public static UserBattle genUpBattleAttr(UserAttr attr, int stage) {
        StageEnum stageEnum = StageEnum.getById(stage);
        double rate = (double) stageEnum.getRate();
        return genUpBattleAttrByRate(attr, rate);
    }

}
